import Vue from 'vue'
import Vuex from 'vuex'

import { getItem, setItem } from '@/uitls/storage'
Vue.use(Vuex)

const TOKEN_KEY = 'TOUTIAO_USER'

export default new Vuex.Store({
  state: {
    // 用户登录状态信息
    user: getItem(TOKEN_KEY)
    // user: JSON.parse(window.localStorage.getItem('TOUTIAO_USER'))
    // USER: Unll
  },
  mutations: {
    setUser (state, user) {
      state.user = user

      // 为了防止刷新丢失,我们要把数据备份到本地储存
      setItem(TOKEN_KEY, state.user)
      // window.localStorage.setItem('TOUTIAO_USER', JSON.stringify(state.user))
    }
  },
  actions: {
  },
  modules: {
    atr: {
      namespaced: true,
      state: {
        cont: 100
      },
      mutations: {
        add (state, pola) {
          state.cont = pola
        }
      },
      actions: {},
      getters: {}
    }
  }
})
